{% extends "Froxlor/userarea.html.twig" %}

{% block content %}
	<h3 class="page-header">{{ lng('panel.dashboard') }}</h3>

	{% if get_setting('panel.is_configured') == 0 and userinfo.adminsession == 1 and userinfo.change_serversettings == 1 %}
		<div class="alert alert-info position-relative p-5">
			<h3>{{ lng('welcome.title') }}</h3>
			<p class="lead mb-5">{{ lng('welcome.config_note') }}</p>
			<a class="btn btn-lg btn-light text-info" href="{{ linker({'section': 'configfiles', 'page': 'configfiles'}) }}">{{ lng('welcome.config_now') }}</a>
			<aside class="position-absolute bottom-0 end-0 p-5 d-none d-md-block">
				<i class="fa-solid fa-hat-wizard fa-5x"></i>
			</aside>
		</div>
	{% endif %}

	<div class="card">
		{% import "Froxlor/user/dashboard-item.html.twig" as dashboard %}
		{% if userinfo.adminsession == 1 %}
			{# admin-resources #}
			<div class="row row-cols-1 row-cols-sm-2 row-cols-xl-5 g-0">
				{{ dashboard.ditem('admin.customers', userinfo.customers, overview.number_customers) }}
				{{ dashboard.ditem('admin.domains', userinfo.domains, overview.number_domains) }}
				{{ dashboard.ditem('customer.diskspace', userinfo.diskspace_bytes, overview.diskspace_bytes_used, overview.diskspace_bytes, true) }}
				{{ dashboard.ditem('customer.traffic', userinfo.traffic_bytes, overview.traffic_bytes_used, overview.traffic_bytes, true) }}
				{{ dashboard.ditem('customer.subdomains', userinfo.subdomains, overview.subdomains_used, overview.subdomains_assigned) }}
				{{ dashboard.ditem('customer.mysqls', userinfo.mysqls, overview.mysqls_used, overview.mysqls_assigned) }}
				{{ dashboard.ditem('customer.emails', userinfo.emails, overview.emails_used, overview.emails_assigned) }}
				{{ dashboard.ditem('customer.accounts', userinfo.email_accounts, overview.email_accounts_used, overview.email_accounts_assigned) }}
				{{ dashboard.ditem('customer.forwarders', userinfo.email_forwarders, overview.email_forwarders_used, overview.email_forwarders_assigned) }}
				{{ dashboard.ditem('customer.ftps', userinfo.ftps, overview.ftps_used, overview.ftps_assigned) }}
			</div>
		{% else %}
			{# customer-resources #}
			<div class="row row-cols-1 row-cols-sm-2 row-cols-xl-4 g-0">
				{{ dashboard.ditem('customer.total_diskspace', userinfo.diskspace_bytes, userinfo.total_bytes_used, null, true) }}
				{{ dashboard.ditem('customer.diskspace', userinfo.diskspace_bytes, userinfo.diskspace_bytes_used, null, true) }}
				{{ dashboard.ditem('customer.traffic', userinfo.traffic_bytes, userinfo.traffic_bytes_used, null, true) }}
				{{ dashboard.ditem('customer.subdomains', userinfo.subdomains, userinfo.subdomains_used) }}
				{{ dashboard.ditem('customer.mysqls', userinfo.mysqls, userinfo.mysqls_used, null, false, userinfo.dbspace_used) }}
				{{ dashboard.ditem('customer.emails', userinfo.emails, userinfo.emails_used) }}
				{{ dashboard.ditem('customer.accounts', userinfo.email_accounts, userinfo.email_accounts_used, null, false, userinfo.mailspace_used) }}
				{{ dashboard.ditem('customer.forwarders', userinfo.email_forwarders, userinfo.email_forwarders_used) }}
				{% if get_setting('system.mail_quota_enabled') and userinfo.email_quota != '0' %}
					{{ dashboard.ditem('customer.email_quota', userinfo.email_quota_bytes, userinfo.email_quota_bytes_used, null, true) }}
				{% endif %}
				{{ dashboard.ditem('customer.ftps', userinfo.ftps, userinfo.ftps_used) }}
			</div>
		{% endif %}
	</div>

	<div class="row">
		{% if userinfo.adminsession == 1 %}
			<div
				class="col-12 col-lg-6">
				{# system infos #}
				<div class="card mb-3">
					<div class="card-header">
						<i class="fa-solid fa-gears me-1"></i>
						{{ lng('admin.systemdetails') }}
						<div class="float-end">
							<button id="copySysInfo" class="btn btn-outline-secondary" style="--bs-btn-padding-y: .25rem; --bs-btn-padding-x: .5rem; --bs-btn-font-size: .5rem;" title="Copy to clipboard"><i class="fa-solid fa-copy"></i></button>
						</div>
						<div id="ccSysInfo" class="d-none">
- Froxlor: {{ call_static('\\Froxlor\\Froxlor', 'getVersionString') }}
- {{ lng('serversettings.update_channel.title') }}: {{ get_setting('system.update_channel') }}
- {{ lng('admin.serversoftware') }}: {{ sysinfo.webserver }}
- {{ lng('admin.phpversion') }}: {{ sysinfo.phpversion }}
- {{ lng('admin.mysqlserverversion') }}: {{ sysinfo.mysqlserverversion }}
- {{ lng('admin.webserverinterface') }}: {{ sysinfo.phpsapi }}
- Kernel: {{ sysinfo.kernel }}
- OS: {{ get_setting('system.distribution') }}
						</div>
					</div>
					<ul class="list-group list-group-flush">
						<li class="list-group-item d-flex justify-content-between align-items-start">
							<div class="ms-2 me-auto">
								<div class="fw-bold">{{ lng('admin.hostname') }}</div>
								{{ sysinfo.hostname }}
							</div>
						</li>
						<li class="list-group-item d-flex justify-content-between align-items-start">
							<div class="ms-2 me-auto">
								<div class="fw-bold">{{ lng('admin.serversoftware') }}</div>
								{{ sysinfo.webserver }}
							</div>
						</li>
						<li class="list-group-item d-flex justify-content-between align-items-start">
							<div class="ms-2 me-auto">
								<div class="fw-bold">{{ lng('admin.phpversion') }}</div>
								<a href="{{ linker({'section':'settings','page':'phpinfo'}) }}">{{ sysinfo.phpversion }}</a>
							</div>
						</li>
						<li class="list-group-item d-flex justify-content-between align-items-start">
							<div class="ms-2 me-auto">
								<div class="fw-bold">{{ lng('admin.mysqlserverversion') }}</div>
								{{ sysinfo.mysqlserverversion }}
							</div>
						</li>
						<li class="list-group-item d-flex justify-content-between align-items-start">
							<div class="ms-2 me-auto">
								<div class="fw-bold">{{ lng('admin.webserverinterface') }}</div>
								{{ sysinfo.phpsapi }}
							</div>
						</li>
						{% if sysinfo.memory is not empty %}
							<li class="list-group-item d-flex justify-content-between align-items-start">
								<div class="ms-2 me-auto">
									<div class="fw-bold">{{ lng('admin.memory') }}</div>
									<pre>{{ sysinfo.memory }}</pre>
								</div>
							</li>
						{% endif %}
						<li class="list-group-item d-flex justify-content-between align-items-start">
							<div class="ms-2 me-auto">
								<div class="fw-bold">{{ lng('admin.sysload') }}</div>
								{{ sysinfo.load }}
							</div>
						</li>
						{% if sysinfo.kernel is not empty %}
							<li class="list-group-item d-flex justify-content-between align-items-start">
								<div class="ms-2 me-auto">
									<div class="fw-bold">Kernel</div>
									{{ sysinfo.kernel }}
								</div>
							</li>
						{% endif %}
						{% if sysinfo.uptime is not empty %}
							<li class="list-group-item d-flex justify-content-between align-items-start">
								<div class="ms-2 me-auto">
									<div class="fw-bold">Uptime</div>
									{{ sysinfo.uptime }}
								</div>
							</li>
						{% endif %}
					</ul>
				</div>

				{% if userinfo.custom_notes|markdown is not empty and userinfo.custom_notes_show == 1 %}
					<div class="card mb-3">
						<ul class="list-group list-group-flush">
							<li class="list-group-item list-group-item-info d-flex justify-content-between align-items-start">
								<div class="ms-2 me-auto">
									{{ userinfo.custom_notes|markdown|raw }}
								</div>
							</li>
						</ul>
					</div>
				{% endif %}
			</div>
		{% else %}
			<div
				class="col-12 col-md-6 col-lg-4">
				{# account info #}
				<div class="card mb-3">
					<div class="card-header">
						<i class="fa-solid fa-user me-1"></i>
						{{ lng('index.accountdetails') }}
					</div>
					<ul class="list-group list-group-flush">
						<li class="list-group-item d-flex justify-content-between align-items-start">
							<div class="ms-2 me-auto">
								<div class="fw-bold">{{ lng('login.username') }}</div>
								{{ userinfo.loginname }}
							</div>
						</li>
						<li class="list-group-item d-flex justify-content-between align-items-start">
							<div class="ms-2 me-auto">
								<div class="fw-bold">{{ lng('customer.email') }}</div>
								{{ userinfo.email }}
							</div>
						</li>
						<li class="list-group-item d-flex justify-content-between align-items-start">
							<div class="ms-2 me-auto">
								<div class="fw-bold">{{ lng('customer.services') }}</div>
								{% if userinfo.imap == 1 %}
									<span class="badge bg-success">IMAP</span>
								{% endif %}
								{% if userinfo.pop3 == 1 %}
									<span class="badge bg-success">POP3</span>
								{% endif %}
								{% if userinfo.phpenabled == 1 %}
									<span class="badge bg-success">PHP</span>
								{% endif %}
								{% if userinfo.perlenabled == 1 %}
									<span class="badge bg-success">Perl/CGI</span>
								{% endif %}
								{% if userinfo.api_allowed == 1 %}
									<a href="{{ linker({'section':'index','page':'apikeys'}) }}">
										<span class="badge bg-success">API</span>
									</a>
								{% endif %}
							</div>
						</li>
						{% if stdsubdomain is not empty %}
							<li class="list-group-item d-flex justify-content-between align-items-start">
								<div class="ms-2 me-auto">
									<div class="fw-bold">{{ lng('admin.stdsubdomain') }}</div>
									{{ stdsubdomain }}
								</div>
							</li>
						{% endif %}
						<li class="list-group-item d-flex justify-content-between align-items-start">
							<div class="ms-2 me-auto">
								<div class="fw-bold">{{ lng('customer.domains') }}</div>
								{% for domain in domains %}
									{{ domain }}<br>
								{% endfor %}
							</div>
							<span class="badge bg-primary rounded-pill">{{ domains|length }}</span>
						</li>
					</ul>
				</div>
			</div>
			<div
				class="col-12 col-md-6 col-lg-4">
				{# customer details #}
				<div class="card">
					<div class="card-header">
						<i class="fa-solid fa-id-card me-1"></i>
						{{ lng('index.customerdetails') }}
					</div>
					<ul class="list-group list-group-flush">
						{% if userinfo.customernumber is not empty %}
							<li class="list-group-item d-flex justify-content-between align-items-start">
								<div class="ms-2 me-auto">
									<div class="fw-bold">{{ lng('customer.customernumber') }}</div>
									{{ userinfo.customernumber }}
								</div>
							</li>
						{% endif %}
						{% if userinfo.company is not empty %}
							<li class="list-group-item d-flex justify-content-between align-items-start">
								<div class="ms-2 me-auto">
									<div class="fw-bold">{{ lng('customer.company') }}</div>
									{{ userinfo.company }}
								</div>
							</li>
						{% endif %}
						{% if userinfo.name is not empty %}
							<li class="list-group-item d-flex justify-content-between align-items-start">
								<div class="ms-2 me-auto">
									<div class="fw-bold">{{ lng('customer.name') }}</div>
									{{ userinfo.firstname }}
									{{ userinfo.name }}
								</div>
							</li>
						{% endif %}
						{% if userinfo.street is not empty %}
							<li class="list-group-item d-flex justify-content-between align-items-start">
								<div class="ms-2 me-auto">
									<div class="fw-bold">{{ lng('customer.street') }}</div>
									{{ userinfo.street }}
								</div>
							</li>
						{% endif %}
						{% if userinfo.city is not empty %}
							<li class="list-group-item d-flex justify-content-between align-items-start">
								<div class="ms-2 me-auto">
									<div class="fw-bold">{{ lng('customer.zipcode') }}/{{ lng('customer.city') }}</div>
									{{ userinfo.zipcode }}
									{{ userinfo.city }}
								</div>
							</li>
						{% endif %}
						{% if userinfo.custom_notes|markdown is not empty and userinfo.custom_notes_show == 1 %}
							<li class="list-group-item list-group-item-info d-flex justify-content-between align-items-start">
								<div class="ms-2 me-auto">
									{{ userinfo.custom_notes|markdown|raw }}
								</div>
							</li>
						{% endif %}
					</ul>
				</div>
			</div>
		{% endif %}
		<div class="col-12 {% if userinfo.adminsession == 1 %}col-lg-6{% else %}col-lg-4{% endif %}">
			{% if userinfo.adminsession == 1 %}
				{# froxlor-details #}
				<div class="card mb-3">
					<div class="card-header">
						<i class="fa-solid fa-wrench me-1"></i>
						{{ lng('admin.froxlordetails') }}
					</div>
					<ul class="list-group list-group-flush">
						<li class="list-group-item d-flex justify-content-between align-items-start">
							<div class="ms-2 me-auto">
								<div class="fw-bold">{{ lng('tasks.outstanding_tasks') }}</div>
								{% for task in outstanding_tasks %}
									<i class="fa-regular fa-clock"></i>
									{{ task.desc }}<br>
								{% endfor %}
							</div>
						</li>
						{% for cronrun in cron_last_runs %}
							<li class="list-group-item d-flex justify-content-between align-items-start">
								<div class="ms-2 me-auto">{{ cronrun.title }}</div>
								<span class="badge bg-primary">
									{% if cronrun.lastrun > 0 %}
										{{ cronrun.lastrun|date('d.m.Y H:i') }}
									{% else %}
										{{ lng('cronjobs.notyetrun') }}
									{% endif %}
								</span>
							</li>
						{% endfor %}
					</ul>
				</div>
			{% endif %}

			{% if (get_setting('admin.show_news_feed') == 1 and userinfo.adminsession == 1) or (get_setting('customer.show_news_feed') == 1 and userinfo.adminsession == 0)  %}
				<div id="newsfeed" class="card" {% if userinfo.adminsession == 0 %} data-role="customer" {% endif %}>
					<div class="card-header">
						<i class="fa-solid fa-info-circle me-1"></i>
						{% if get_setting('customer.news_feed_url') is empty %}Froxlor
						{% endif %}Newsfeed
					</div>
					<div class="list-group list-group-flush" id="newsfeeditems">
						<div class="list-group-item d-flex justify-content-between align-items-start">
							<div class="ms-2 me-auto">
								Loading newsfeed...
							</div>
							<span>
								<i class="fa-solid fa-spinner fa-spin"></i>
							</span>
						</div>
					</div>
				</div>
			{% endif %}
		</div>
	</div>
{% endblock %}
